<?php
/*
	自动安装基础功能插件和组件模版
*/
defined('BY_JYA') or exit('error');
if(!$_SESSION['isfounder']){
	exi('无权访问！','error','core/account.siteinfo/');
}
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
if($_RQ['op']=='main'){
	$return['apps']=array(
		array('title'=>'功能插件','get_op'=>'plugin','install_action'=>'cloud.module'),
		array('title'=>'手机页面组件','get_op'=>'mobile_block','install_action'=>'cloud.mobile_blocks'),
		array('title'=>'PC页面组件','get_op'=>'pc_block','install_action'=>'cloud.pc_blocks'),
		array('title'=>'微站模版','get_op'=>'mobile_template','install_action'=>'cloud.mobile_template'),
		array('title'=>'PC站模版','get_op'=>'pc_template','install_action'=>'cloud.pc_template'),
	);
	exi($return);
}
if($_RQ['op']=='plugin'){
	//获取待安装功能插件
	$installed = pdo_getall('core_plugins',array(),array('cloud_id'),'cloud_id');
	$installed=array_keys($installed);
	$installed=implode(';',$installed);
	$list=cloud_request('update.plugin.getbuyed',array('installed'=>$installed));	
	foreach($list as $key=>&$item){
		if(!is_dir(ROOT_PLUGIN.$item['name'])){
			unset($list[$key]);
		}else{
			$item=array_fields(array('id','title'),$item);
		}
	}
	$list=array_values($list);
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='mobile_block'){
	//获取待安装手机页面组件
	$installed = pdo_getall('core_mobile_blocks',array(),array('cloud_id'),'cloud_id');
	$installed=array_keys($installed);
	$installed=implode(';',$installed);
	$list=cloud_request('update.mobile_blocks.getbuyed',array('installed'=>$installed));
	foreach($list as &$item){
		$item=array_fields(array('id','title'),$item);
	}
	$list=array_values($list);
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='pc_block'){
	//获取待安装pc页面组件
	$installed = pdo_getall('core_pc_blocks',array(),array('cloud_id'),'cloud_id');
	$installed=array_keys($installed);
	$installed=implode(';',$installed);
	$list=cloud_request('update.pc_blocks.getbuyed',array('installed'=>$installed));
	foreach($list as &$item){
		$item=array_fields(array('id','title'),$item);
	}
	$list=array_values($list);
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='mobile_template'){
	//获取待安装微站模版
	$installed = pdo_getall('core_mobile_template',array('uniacid'=>0),array('cloud_id'),'cloud_id');
	$installed=array_keys($installed);
	$installed=implode(';',$installed);
	$list=cloud_request('update.mobile_template.getbuyed',array('installed'=>$installed));
	foreach($list as &$item){
		$item=array_fields(array('id','title'),$item);
	}
	$list=array_values($list);
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='pc_template'){
	//获取待安装微站模版
	$installed = pdo_getall('core_pc_template',array('uniacid'=>0),array('cloud_id'),'cloud_id');
	$installed=array_keys($installed);
	$installed=implode(';',$installed);
	$list=cloud_request('update.pc_template.getbuyed',array('installed'=>$installed));
	foreach($list as &$item){
		$item=array_fields(array('id','title'),$item);
	}
	$list=array_values($list);
	$return['list']=$list;
	exi($return);
}
